package susebs.pb.travel_server.controller;

import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import susebs.pb.travel_server.domain.NavigationResponse;
import susebs.pb.travel_server.domain.PageDto;
import susebs.pb.travel_server.domain.Result;
import susebs.pb.travel_server.entity.Rooms;
import susebs.pb.travel_server.service.NavigationsService;
import susebs.pb.travel_server.service.RoomsService;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 *房间控制层
 */
@RestController
@RequestMapping("/rooms")
@CrossOrigin
public class RoomsController {
    @Resource
    private RoomsService roomsService;
    @Resource
    private NavigationsService navigationsService;

    /**
     * 查询指定酒店的所有房间数据
     * @param hotelId 酒店id
     * @return 指定酒店的房间列表
     */
    @GetMapping("/queryAllRoomsByHotelId")
    public Result queryAllRoomsByHotelId(Long hotelId){
        List<Rooms> list = roomsService.queryAllRooms(hotelId);
        ArrayList<NavigationResponse> res = navigationsService.getListsAndPics(list);
        return Result.buildSuccess(res);
    }

    //管理
    //查
    @PostMapping("/queryByPage")
    public Result queryByPage(@RequestBody PageDto pageDto){
        PageInfo list = roomsService.queryAllRoomsByPage(pageDto);
        if(list.getList().isEmpty())return Result.buildFail("无房间数据");
        ArrayList res = navigationsService.getListsAndPics(list.getList());
        return Result.buildSuccess(res);
    }
    //删
    @GetMapping("/deleteById")
    public Result deleteById(Long roomId){
        boolean delete = roomsService.deleteById(roomId);
        if(delete)return Result.buildSuccess();
        return Result.buildFail("删除失败！");
    }























}
